﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using Tzx.Utilities;

namespace Tzx.Tools.Payroll2Images.Exe
{
    /// <summary>
    /// 本应用帮助
    /// </summary>
    public class App
    {
        /// <summary>
        /// 本应用程序名称标题
        /// </summary>
        public const string Title = "消息分发器";

        /// <summary>
        /// 本应用程序“功能和应用场景”文本
        /// </summary>
        public static readonly string TEXT_App_Description =
            "功能及应用场景：" + Environment.NewLine + Environment.NewLine +
            "从Excel表格文件中读取数据表（如工资补贴表），" +
            "按模板一行导出一个图片（工资条），" +
            "然后将图片文件分别发送给相应职员。" +
            "" +
            "";

        /// <summary>
        /// 本应用程序“关于”文本
        /// </summary>
        public static readonly string TEXT_App_About =
            "关于：" + Environment.NewLine + Environment.NewLine +
            "（1）程序修改请联系：" + "微信：mLangTang_com / QQ及邮箱：575780781@qq.com" + Environment.NewLine + Environment.NewLine +
            "（2）程序版本号：" + VersionText + Environment.NewLine + Environment.NewLine +
            "（3）程序最后编译时间：" + Version_Date + " " + Version_Time + Environment.NewLine + Environment.NewLine +
            "" +
            "";

        #region 版本信息

        /// <summary>
        /// 版本号
        /// </summary>
        public static string VersionText
        {
            get
            {
                if (_versionText == null)
                {
                    Version appVer = Assembly.GetExecutingAssembly().GetName().Version;
                    if (appVer != null)
                    {
                        string verString = appVer.ToString();
                        _versionText = verString;
                        return verString;
                    }
                    else
                    {
                        _versionText = "-";
                    }
                }
                return _versionText;
            }
        }
        private static string _versionText = null;

        /// <summary>
        /// 版本号_日期
        /// </summary>
        public static string Version_Date
        {
            get
            {
                if (_version_Date == null)
                {
                    RenewVersionDateTime();
                }
                if (_version_Date == null)
                {
                    _version_Date = "-";
                }
                return _version_Date;
            }
        }
        private static string _version_Date;

        /// <summary>
        /// 版本号_时间
        /// </summary>
        public static string Version_Time
        {
            get
            {
                if (_version_Time == null)
                {
                    RenewVersionDateTime();
                }
                if (_version_Time == null)
                {
                    _version_Time = "-";
                }
                return _version_Time;
            }
        }
        private static string _version_Time;

        /// <summary>
        /// 版本号_刷新日期时间
        /// </summary>
        private static void RenewVersionDateTime()
        {
            Version appVer = Assembly.GetExecutingAssembly().GetName().Version;
            if (appVer == null)
            {
                _version_Date = "-";
                _version_Time = "-";
                return;
            }

            string verString = appVer.ToString();
            string[] ssVerText = verString.Split('.');
            string verDay = null; //编译日期(从2000-1-1到编译日的天数)
            string verTime = null; //编译时间(从 0:00:00到编译时的刻度数/两秒数)

            //日期
            if (ssVerText.Length >= 3)
            {
                //第3位是日期
                string s = ssVerText[2];
                if (Regex.IsMatch(s, @"^\d{1,}$"))
                {
                    int day;
                    if (int.TryParse(s, out day))
                    {
                        //编译日期
                        verDay = (new DateTime(2000, 1, 1)).AddDays(day).ToString("yyyy-MM-dd");
                    }
                }
            } //日期

            //时间
            if (ssVerText.Length >= 4)
            {
                string s = ssVerText[3];
                if (Regex.IsMatch(s, @"^\d{1,}$"))
                {
                    int second2;
                    if (int.TryParse(s, out second2))
                    {
                        //编译时间
                        DateTime dt = (new DateTime(2000, 1, 1, 0, 0, 0, 0));
                        DateTime dt2 = dt.AddSeconds(second2 * 2); //两秒
                        verTime = dt2.ToString("HH:mm"); //verTime = dt2.ToString("HH:mm:ss");
                    }
                }
            } //时间

            if (string.IsNullOrEmpty(verDay)) verDay = "-";
            if (string.IsNullOrEmpty(verTime)) verTime = "-";

            //设置
            _version_Date = verDay;
            _version_Time = verTime;
        }

        #endregion

        #region 列名

        /// <summary>
        /// 导入表关联列名:中文名
        /// </summary>
        public static string ColumnName_Import_CnName = "中文名";

        /// <summary>
        /// 导入表关联列名:英文名
        /// </summary>
        public static string ColumnName_Import_EnName = "英文名";

        /// <summary>
        /// 导入表关联列名:工号
        /// </summary>
        public static string ColumnName_Import_JobNumber = "工号";


        /// <summary>
        /// 导入表新增列名:唯一行字段
        /// </summary>
        public const string ColumnFixName_FID = "FID_" + TEXT_GUID;

        /// <summary>
        /// 导入表新增列名:显示接收人名称(中文名,英文名,工号)
        /// </summary>
        public const string ColumnFixName_FEmployeeAllName = "FNAME_" + TEXT_GUID;

        /// <summary>
        /// 唯一防重复码
        /// </summary>
        private const string TEXT_GUID = "7b12778051f54f9297a6fae8ceda5aaf";

        #endregion

        #region 公共文本

        /// <summary>
        /// 发送文件夹名称
        /// </summary>
        public const string TEXT_FolderName_Receiver = "发送";

        #endregion

    }

    /// <summary>
    /// 
    /// </summary>
    class ZBug
    {
        /// <summary>
        /// 仅在DEBUG时记录日志
        /// </summary>
        /// <param name="text"></param>
        [Conditional("DEBUG")]
        public static void Log(params string[] text)
        {
            List<string> textSs = new List<string>(new string[] { typeof(ZBug).Name });
            textSs.AddRange(text);

            //记录日志
            LogFile.Me.LogText(textSs.ToArray());
        }

    }
}
